package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
@Transactional
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 新增跟进线索(更新跟进线索，插入跟进记录)
     * @param tbClueTrackRecord
     */
    @Override
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        //更新跟进线索
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClue.setCreateBy(SecurityUtils.getUsername());
        tbClue.setUpdateTime(new Date());
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbClueTrackRecordMapper.add(tbClue);
        //插入跟进记录
        TbClueTrackRecord clueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord,clueTrackRecord);
        clueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        clueTrackRecord.setUpdateTime(new Date());
        clueTrackRecord.setCreateTime(new Date());
        clueTrackRecord.setType("0");
        tbClueTrackRecordMapper.record(clueTrackRecord);
    }

    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        List<TbClueTrackRecord> list = tbClueTrackRecordMapper.list(clueId);
        return list;
    }
}
